package com.basic.library.utils;

import android.view.View;

import java.util.Calendar;

/**
 * @author jiangyun
 * @description
 * @time 创建时间：2017/11/22 16:00
 */
public abstract class NoDoubleClickListener implements View.OnClickListener {

    public static int MIN_CLICK_DELAY_TIME = 600;// 这里设置不能超过多长时间
    private long lastClickTime = 0;

    protected abstract void onNoDoubleClick(View v);

    public NoDoubleClickListener() {
    }

    public NoDoubleClickListener(int time) {
        MIN_CLICK_DELAY_TIME = time;
    }

    @Override
    public void onClick(View v) {
        long currentTime = Calendar.getInstance().getTimeInMillis();
        if (currentTime - lastClickTime > MIN_CLICK_DELAY_TIME) {
            lastClickTime = currentTime;
            onNoDoubleClick(v);
        }
    }
}
